﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CardMgr : MonoBehaviour
{
    public GameObject mCardGameobject = null;

    private static CardMgr _instance { get; set; }
    public static CardMgr GetInstance
    {
        get
        {
            if (_instance == null)
            {
                _instance = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CardMgr>();
                if (_instance == null)
                {
                    _instance = GameObject.FindGameObjectWithTag("MainCamera").AddComponent<CardMgr>();
                }                
            }
            return _instance; ;
        }
    }

    private void Start()
    {
        GameObject[] cards = GameObject.FindGameObjectsWithTag("Card");
        foreach (var item in cards)
        {
            CardTriggerListener listener = item.GetComponent<CardTriggerListener>();
            if (listener == null)
            {
                listener = item.AddComponent<CardTriggerListener>();
            }

            listener.carOnPointDown = OnMouseDown;
        }
    }

    //回调
    private void OnMouseDown(GameObject gameObject)
    {
        mCardGameobject = gameObject;
        //标记改卡片为已选择
        gameObject.transform.Find("direction").GetComponent<CanvasGroup>().alpha = 1;
    }

    private void Update()
    {
        
    }
}
